﻿{extend name="admin/common/common2"/}
	{block name="main"}
             


<div class="layui-row">
    <div class="layui-col-xs6 opreate">
		<div class="layui-btn-group addbtn">
		  <a class="layui-btn"  data-type="add" >添加信息</a>
		</div>
		<div class="layui-btn-group ckbtn">
		  <button class="layui-btn" data-type="ck"  >查看信息</button>
		</div>
    </div>
    <div class="layui-col-xs6">
	<form class="layui-form" action="">
		<div class="search">
		  搜索条件：
		  <div class="layui-inline">
			
				
				  <select name="condition" >
					<option value="" selected=""></option>
					{volist name="tableframe" id="vo"}
						<option value="{$vo.Field}">{$vo.Comment}</option>
					{/volist}
				</select>
				
		  </div>
		  <div class="layui-inline">
			<input class="layui-input" name="id" id="demoReload" lay-verify="required" autocomplete="off">
		  </div>
		  <button class="layui-btn" lay-submit="" lay-filter="searchbtn" data-type="reload">搜索</button>
		</div>
		</form>
    </div>
  </div>
 
<table class="layui-hide" id="datagrid" lay-filter="datagrid"></table> 
     
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" id="del" lay-event="del">删除</a>
</script>
 
		<script>
		var qxm={$qxm};
		if(qxm['add']==0)
		{
			$('.addbtn').hide();
		}
		if(qxm['search']==0)
		{
			$('.search').hide();
		}
		if(qxm['ck']==0)
		{
			$('.ckbtn').hide();
		}
		layui.use(['form','table','layer'], function(){
		  var table = layui.table
		  ,form = layui.form
		  ,layer= layui.layer;
		  
		  //方法级渲染
		  table.render({
			elem: '#datagrid'
			,url: '__ROOT__/admin/service/select'
			,cols: [[
			  {checkbox: true, fixed: true}
			  {$datagridfield}
			  ,{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}
			]]
			,where:{flag:'{$tablename}'}
			,page: true

		  });
		  
		    //监听工具条
			  table.on('tool(datagrid)', function(obj){
				
				var data = obj.data;
				if(obj.event === 'del'){
				
				if(qxm['del']!=0)
				{
					
				
				  layer.confirm('真的删除行么', function(index){
					$.ajax({
            //几个参数需要注意一下
					type: "post",//方法类型
					dataType: "json",//预期服务器返回的数据类型
					async:true,
					url: "{:url('admin/service/del','','')}" ,//url
					data: {'id':obj.data.id,'table':'{$tablename}'},
					success: function (result) {
						layer.alert('成功', {
						  skin: 'layui-layer-molv', //样式类名
						  title: '提示'
						});
					}
				});
					obj.del();
					layer.close(index);
					
				  });
				  }
				  else {
					layer.alert('你没有删除权限！');
				  }
				} else if(obj.event === 'edit'){
				if(qxm['edit']!=0)
				{
				
				  var str = "{:url('admin/index/edit?id=data.id&table='.$tablename)}"; 
				  str1 =  str.replace("data.id",data.id);
				  layer.open({
					  type: 2,
					  title: '编辑',
					  iframeScrolling:true,
					  skin: 'layui-layer-rim',
					  area: ['80%','550px'],
					  content: str1,
					  maxmin: true,
					  success: function (result) {
						table.reload('datagrid', {
				  url: '__ROOT__/admin/service/select'
				});
					}
					});
					}
				  else {
					layer.alert('你没有编辑权限！');
				  }
				}
				
			  });
			   
				
			    //监听提交
			  form.on('submit(searchbtn)', function(data){
				table.reload('datagrid', {
				  url: '__ROOT__/admin/service/select'
				  ,where: 
				  {
					field:data.field.condition,
					value:data.field.id
				  }
				});
				return false;
			  });
			  var $ = layui.$, active = {
				ck: function(){ //获取选中数据
				  var checkStatus = table.checkStatus('datagrid')
				  ,data = checkStatus.data;
				  if(data.length!=1)
				  {
					layer.alert("请选中一项信息！");
				  }
				  else{
				  
				  layer.open({
					  type: 2,
					  area: ['80%', '90%'], //宽高
					  content: '__ROOT__/admin/index/ck?id='+JSON.stringify(data[0]['id'])
					});
				 
				  }
				}
				,add: function(){ //获取选中数据
				  var index = layer.open({
					  type: 2,
					  area: ['80%', '90%'], //宽高
					  content: "{:url('admin/index/'.$add, '', '')}",
					  success:function(){
						
					}
				
					});
				}
			  };
			  $('.opreate .layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			  });

		});

</script>
	{/block}